<template>
  <div>
    <avue-crud
      ref="crud"
      :page="page"
      :data="dataList"
      :table-loading="dataListLoading"
      :option="tableOption"
      @search-change="searchChange"
      @on-load="getDataList"
      @refresh-change="refreshChange"
    >
      <template slot-scope="scope" slot="status">
        <el-tag v-if="scope.row.status === -1" type="danger" size="small">
          {{$t('station.auditFailure') }}
        </el-tag>
        <el-tag v-if="scope.row.status === 1" type="success" size="small">{{
            $t('station.successfulAudit')
          }}</el-tag>
        <el-tag v-else-if="scope.row.status === 0" size="small">{{
            $t('station.underReview')
          }}</el-tag>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text" @click="handleDetail(scope.row)" size="medium">{{$t('shop.withdrawalDetail')}}</el-button>
      </template>
    </avue-crud>
    <withdrawal ref="detail" v-if="detailVisible"/>
  </div>
</template>

<script>
import { tableOption } from '@/crud/shop/shopWalletLogWithdrawal'
import Withdrawal from './withdrawal-detail.vue'

export default {
  data () {
    return {
      detailVisible: false,
      dataList: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      searchForm: {}, // 搜索
      dataListLoading: false,
      tableOption: tableOption
    }
  },
  components: {
    Withdrawal
  },
  methods: {
    getDataList (page) {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/shop/withdrawCash/page'),
        method: 'get',
        params: this.$http.adornParams(
          Object.assign(
            {
              current: page == null ? this.page.currentPage : page.currentPage,
              size: page == null ? this.page.pageSize : page.pageSize
            },
            this.searchForm
          )
        )
      }).then(({ data }) => {
        console.log(data)
        this.dataList = data.records
        this.page.total = data.total
        this.dataListLoading = false
      })
    },
    handleDetail (rowData) {
      this.detailVisible = true
      this.$nextTick(() => {
        this.$refs.detail.init(rowData)
      })
    },
    /**
     * 刷新回调
     */
    refreshChange () {
      this.isCashWithdrawal = false
      this.page = this.$refs.crud.$refs.tablePage.defaultPage
      this.getDataList(this.page)
      this.getShopWalletInfo()
    },
    searchChange (params) {
      this.searchForm = params
      this.getDataList(this.page)
    }
  }
}
</script>
